package main

import (
	"fmt"
)

//奇偶排序
func oddEven(arr []int) []int {
	isSort := false //标记是有数据交换

	if len(arr) <= 1 {

	} else {
		for isSort == false {
			isSort = true
			for i := 0; i < len(arr)-1; i += 2 {
				if arr[i] > arr[i+1] {
					arr[i], arr[i+1] = arr[i+1], arr[i]
					isSort = false
				}
			}

			for i := 1; i < len(arr)-1; i += 2 {
				if arr[i] > arr[i+1] {
					arr[i], arr[i+1] = arr[i+1], arr[i]
					isSort = false
				}
			}
			fmt.Println(arr)
		}
	}
	return arr
}

/**

[3 2 59 4 6 9 13 9 78 16 18 22 28]
[2 3 4 6 59 9 9 13 16 18 78 22 28]
[2 3 4 6 9 9 59 13 16 18 22 28 78]
[2 3 4 6 9 9 13 16 59 18 22 28 78]
[2 3 4 6 9 9 13 16 18 22 59 28 78]
[2 3 4 6 9 9 13 16 18 22 28 59 78]
[2 3 4 6 9 9 13 16 18 22 28 59 78]

*/

func main() {
	arr := []int{3, 59, 4, 2, 9, 6, 78, 13, 9, 18, 16, 28, 22}
	oddEven(arr)
}
